home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-24 | 28.9 KB | 1,065 lines | [TEXT/KAHL] |
- //----------------------------------------------------------------------------------
- // File : dialogAssist.c
- // Date : April 4, 1994
- // Author : Jim Stout
- // Purpose : Dialog utilities that make use of ModalDialog a bit easier.
- //
- // I got really tired of writing all those GetDItem/SetDItem calls
- // and then having to mix them with Control Manager and Dialog
- // Manager calls (that have various syntax rules). So, these are
- // are a start at some easier routines.
- //
- // Also, there are routines here for handling keys, limits on
- // editText DITL items, mouseClicks, cursors and dimming items -
- // and lots of other stuff. Take a look at the dialogAssist.h
- // file prototypes - the routine names are pretty self explanatory.
- //----------------------------------------------------------------------------------
-
- #include <GestaltEqu.h>
- #include <Traps.h>
- #include "dialogAssist.h"
- #include "dimText.h"
-
- #define BEEP 1
-
- #pragma mark _ControlRoutines
-
- //----------------------------------------------------------------------------------
- // Function: daToggleCheck
- // Purpose: toggles the state of a checkbox.
- // Does nothing if called for a non-checkbox item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daToggleCheck (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & chkCtrl)) {
- SetCtlValue(h, !GetCtlValue(h));
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daToggleRadio
- // Purpose: set radio button "i" ON and turns the others off.
- // N.B. This routine assumes that radio buttons are
- // sequentially numbered from "first" to "last"
- // Does nothing if called for a non-radioBtn item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daToggleRadio (DialogPtr d, short i, short first, short last)
- {
- short t,inx;
- ControlHandle h;
- Rect r;
-
- for(inx=first;inx<=last;inx++) {
- GetDItem(d, inx, &t, (Handle *)&h, &r);
- if(h && (t & radCtrl)) {
- if(inx == i)
- SetCtlValue(h, ON);
- else
- SetCtlValue(h, OFF);
- }
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetRadio
- // Purpose: Return the number of the "on" radio button in a set.
- // N.B. This routine assumes that radio buttons are
- // sequentially numbered from "first" to "last"
- // Does nothing if called for a non-radioBtn item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- short daGetRadio (DialogPtr d, short first, short last)
- {
- short t,inx;
- ControlHandle h;
- Rect r;
-
- for(inx=first;inx<=last;inx++) {
- GetDItem(d, inx, &t, (Handle *)&h, &r);
- if(h && (t & radCtrl)) {
- if(GetCtlValue(h))
- return(inx);
- }
- }
- return(0);
- }
- //----------------------------------------------------------------------------------
- // Function: daToggleCtl
- // Purpose: toggles the state of a control.
- // Does nothing if called for a non-control item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daToggleCtl (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- SetCtlValue(h, !GetCtlValue(h));
- }
- }
- //----------------------------------------------------------------------------------
- // Function: daGetCtlHandle
- // Purpose: get the handle to a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: value of control
- //----------------------------------------------------------------------------------
- ControlHandle daGetCtlHandle (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- return (h);
- }
- return(0);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetCtlMax
- // Purpose: get the maximum value of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: value of control
- //----------------------------------------------------------------------------------
- short daGetCtlMax (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- return ((**h).contrlMax);
- }
- return(0);
- }
- //----------------------------------------------------------------------------------
- // Function: daGetCtlMin
- // Purpose: get the minimum value of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: value of control
- //----------------------------------------------------------------------------------
- short daGetCtlMin (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- return ((**h).contrlMin);
- }
- return(0);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetCtlValue
- // Purpose: get the value of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: value of control
- //----------------------------------------------------------------------------------
- short daGetCtlValue (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- return (GetCtlValue(h));
- }
- return(0);
- }
- //----------------------------------------------------------------------------------
- // Function: daSetCtlValue
- // Purpose: set the value of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
-
- void daSetCtlValue (DialogPtr d, short i, short newVal)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- SetCtlValue(h, newVal);
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetCtlTitle
- // Purpose: Get the title of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daGetCtlTitle (DialogPtr d, short i, Str255 theTitle)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- pStrCopy((char *)theTitle,(char *)(*h)->contrlTitle);
- }
- }
- //----------------------------------------------------------------------------------
- // Function: daSetCtlTitle
- // Purpose: set the title of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daSetCtlTitle (DialogPtr d, short i, Str255 newTitle)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem)) {
- SetCTitle(h, newTitle);
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetCtlRefCon
- // Purpose: get the refCon of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- // returns: refCon
- //----------------------------------------------------------------------------------
- long daGetCtlRefCon (DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem))
- return(GetCRefCon(h));
- else
- return(0L);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daSetCtlRefCon
- // Purpose: set the refCon of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- //----------------------------------------------------------------------------------
- void daSetCtlRefCon(DialogPtr d, short i,long theValue)
- {
- short theType;
- Rect theRect;
- Handle theCtl;
-
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h && (t & ctrlItem))
- SetCRefCon(h,theValue);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daGetCtlRect
- // Purpose: get the rect of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- //----------------------------------------------------------------------------------
- void daGetCtlRect(DialogPtr d, short i, Rect * r)
- {
- short t;
- ControlHandle h;
- Rect r1;
-
- GetDItem(d, i, &t, (Handle *)&h, &r1);
- if(h && (t & ctrlItem))
- *r = (*h)->contrlRect;
- }
-
- //----------------------------------------------------------------------------------
- // Function: daSetCtlRect
- // Purpose: set the rect of a control item in a dialog.
- // Does nothing if called for a non-control item.
- //
- //----------------------------------------------------------------------------------
- void daSetCtlRect(DialogPtr d, short i, Rect * newRect)
- {
- short t,h,v;
- Rect r;
- ControlHandle theCtl;
-
- GetDItem(d, i, &t, (Handle *)&theCtl, &r);
- if(h && (t & ctrlItem)) {
- h = (*newRect).right - (*newRect).left;
- v = (*newRect).bottom - (*newRect).top;
- SizeControl(theCtl, h, v);
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daIsHidden
- // Purpose: find out if a dialog item is hidden.
- // :
- //
- // returns: true if item is hidden
- //----------------------------------------------------------------------------------
- Boolean daIsHidden(DialogPtr d, short i)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(r.left > 8192)
- return(true);
- return(false);
- }
- #pragma mark _MouseRoutines
-
- //----------------------------------------------------------------------------------
- // Function: daMouseItem
- // Purpose: check entire DITL list for a mouse click in an item.
- // :
- // returns: item clicked
- //----------------------------------------------------------------------------------
- short daMouseWhere (DialogPtr d, EventRecord * theEvt)
- {
- short inx,max,t;
- ControlHandle h;
- Rect r;
- Point mp;
-
- mp = theEvt->where;
- GlobalToLocal(&mp);
-
- max = (**(short **) (((DialogPeek) d)->items)) +1;
- for(inx=1;inx<=max;inx++) {
- GetDItem(d, inx, &t, (Handle *)&h, &r);
- if(PtInRect(mp, &r))
- return(inx);
- }
- return(0);
- }
- //----------------------------------------------------------------------------------
- // Function: daMouseInItem
- // Purpose: check a single DITL item for a mouse click in that item.
- //
- // returns: true if item clicked, false otherwise.
- //----------------------------------------------------------------------------------
- Boolean daMouseInItem (DialogPtr d, short i, EventRecord * theEvt)
- {
- short t;
- ControlHandle h;
- Rect r;
- Point mp;
-
- mp = theEvt->where;
- GlobalToLocal(&mp);
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(PtInRect(mp, &r))
- return(true);
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daEditCursor
- // Purpose: set IBeam cursor if mouse if over the current editText item.
- // typically called from top of dialog filterProc
- // returns: void
- //----------------------------------------------------------------------------------
- void daEditCursor (DialogPtr d)
- {
- short i,t;
- ControlHandle h;
- Rect r;
- Point mp;
-
- i = ((DialogPeek)d)->editField + 1;
- GetMouse(&mp);
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(PtInRect(mp, &r))
- SetCursor(*(GetCursor(1)));
- else
- InitCursor();
- }
- #pragma mark _TextRoutines
- //----------------------------------------------------------------------------------
- // Function: daSetIText
- // Purpose: set text into a DITL item.
- // Does nothing if called for non-editText or non-statText item.
- // returns: void.
- //----------------------------------------------------------------------------------
- void daSetIText (DialogPtr d, short i, Str255 newText)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & statText || t & editText)) {
- SetIText(h, newText);
- }
- }
- //----------------------------------------------------------------------------------
- // Function: daGetIText
- // Purpose: get the text from a DITL item.
- // Does nothing if called for non-editText or non-statText item.
- // returns: void.
- //----------------------------------------------------------------------------------
- void daGetIText (DialogPtr d, short i, Str255 s)
- {
- short t;
- Handle h;
- Rect r;
-
- s[0] = 0;
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & statText || t & editText)) {
- GetIText(h, s);
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daSetINum
- // Purpose: set a number into a DITL item.
- // Does nothing if called for non-editText or non-statText item.
- // returns: void.
- //----------------------------------------------------------------------------------
- void daSetINum (DialogPtr d, short i, long newNum)
- {
- short t;
- Handle h;
- Rect r;
- Str255 s;
-
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & statText || t & editText)) {
- NumToString(newNum, s);
- SetIText(h, s);
- }
- }
- //----------------------------------------------------------------------------------
- // Function: daGetINum
- // Purpose: get the contents a DITL item as a number.
- // Does nothing if called for non-editText or non-statText item.
- // returns: contents of text item as a long.
- //----------------------------------------------------------------------------------
- long daGetINum (DialogPtr d, short i)
- {
- short t;
- Handle h;
- Rect r;
- Str255 s;
- long l=0L;
-
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & statText || t & editText)) {
- GetIText(h, s);
- StringToNum(s, &l);
- }
- return(l);
- }
- //----------------------------------------------------------------------------------
- // Function: daSelIText
- // Purpose: select the text of a DITL editText item.
- // Does nothing if called for a non-editText item.
- // returns: void.
- //----------------------------------------------------------------------------------
- void daSelIText(DialogPtr d, short i)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & editText)) {
- SelIText(d, i, 0,32767);
- }
-
- }
-
- //----------------------------------------------------------------------------------
- // Function: daSetInsert
- // Purpose: set the insertion point for a DITL editText item before character
- // "before". If "before" is zero, set insertion point at end.
- // Does nothing if called for a non-editText item.
- // returns: void.
- //----------------------------------------------------------------------------------
- void daSetInsert(DialogPtr d, short i, short before)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- if(h && (t & editText)) {
- if(before)
- SelIText(d, i, before-1, before-1);
- else
- SelIText(d, i, 32767,32767);
- }
-
- }
- #pragma mark _DefaultButton
-
- //----------------------------------------------------------------------------------
- // Function: daSetDefItem
- // Purpose: set default item (button) for a dialog and redraw it.
- //
- // returns: void.
- //----------------------------------------------------------------------------------
- void daSetDefItem(DialogPtr d, short defItem)
- {
- short t;
- Handle h;
- Rect r;
- PenState ps;
- long cQD;
- RGBColor fg,bg;
-
- GetDItem(d, defItem, &t, &h, &r);
- if(h && (t == 4)) {
- if(((DialogPeek)d)->aDefItem != defItem) {
- GetPenState(&ps);
- cQD = daGestalt(gestaltQuickdrawVersion);
- if(cQD >= gestalt8BitQD) {
- GetForeColor(&fg);
- GetBackColor(&bg);
- RGBForeColor(&bg);
- }
- else
- PenMode(srcXor);
- daDrawDefault(d);
- if(cQD >= gestalt8BitQD)
- RGBForeColor(&fg);
- SetPenState(&ps);
- ((DialogPeek)d)->aDefItem = defItem;
- daDrawDefault(d);
- }
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daDrawDefault
- // Purpose: draws the default button outline.
- // Should be called from filterProc in response to udpdateEvt
- // returns: void.
- //----------------------------------------------------------------------------------
- void daDrawDefault (DialogPtr d)
- {
- short defItem,t;
- Handle h;
- Rect r;
- PenState ps;
-
- defItem = ((DialogPeek)d)->aDefItem;
- GetDItem(d, defItem, &t, &h, &r);
- if(h && (t == 4)) {
- GetPenState(&ps);
- PenSize(3,3);
- InsetRect(&r, -4,-4);
- FrameRoundRect(&r, 16, 16);
- SetPenState(&ps);
- }
-
- }
-
- #pragma mark _KeyRoutines
-
- //----------------------------------------------------------------------------------
- // Function: daShiftSelect
- // Purpose: handle shift arrow key selection.
- // : call from your filter routine if the shiftkey is down and the
- // : right or left arrow keys are pressed.
- //----------------------------------------------------------------------------------
- Boolean daShiftSelect(DialogPtr d, char key)
- {
- short start, end;
-
- if(key != _LEFT && key != _RIGHT)
- return false;
-
- start = (**(*(DialogPeek)d).textH).selStart;
- end = (**(*(DialogPeek)d).textH).selEnd;
- if(key == _LEFT)
- start--;
- else
- if(key == _RIGHT)
- end++;
- if(start >= 0)
- TESetSelect(start, end, (*(DialogPeek)d).textH);
- return true;
- }
- //----------------------------------------------------------------------------------
- // Function: daOptionDown
- // Purpose: check for optionKey press without having an eventRecord.
- //
- // returns: true if option key is pressed.
- //----------------------------------------------------------------------------------
- Boolean daOptionDown()
- {
- KeyMap theKeys;
-
- GetKeys(theKeys);
- if(BitTst(&theKeys[1],29L)) // option key down
- return(true);
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daCmdDown
- // Purpose: check for commandKey press without having an eventRecord.
- //
- // returns: true if command key is pressed.
- //----------------------------------------------------------------------------------
- Boolean daCmdDown()
- {
- KeyMap theKeys;
-
- GetKeys(theKeys);
- if(BitTst(&theKeys[1],16L)) // command key down
- return(true);
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daCntlDown
- // Purpose: check for controlKey press without having an eventRecord.
- //
- // returns: true if control key is pressed.
- //----------------------------------------------------------------------------------
- Boolean daCntlDown()
- {
- KeyMap theKeys;
-
- GetKeys(theKeys);
- if(BitTst(&theKeys[1],28L)) // control key down
- return(true);
- return(false);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daExitKey
- // Purpose: check for a key press that should exit the dialog.
- // Flashes default button (OK) if RETURN or ENTER
- // Flashes cancel button if ESCAPE or cmd-period.
- //
- // returns: true if dialog should be closed.
- //----------------------------------------------------------------------------------
- Boolean daExitKey(DialogPtr d, EventRecord *evt, short *i, short cancelItem)
- {
- short t,defItem;
- char key;
- Handle h;
- Rect r;
- long ticks;
- Boolean result = false;
-
- defItem = ((DialogPeek)d)->aDefItem;
- if(!defItem)
- return;
- key = (evt->message & charCodeMask);
-
- if (key == _RETURNKEY || key == _ENTRKEY){
- GetDItem(d, defItem, &t, &h, &r);
- *i = defItem;
- result = true;
- }
- else
- if (key == _ESCAPEKEY || (key == _PERIODKEY && daCmdDown()) ) {
- GetDItem(d, cancelItem, &t, &h, &r);
- *i = cancelItem;
- result = true;
- }
- if(h && result) {
- HiliteControl((ControlHandle)h,true);
- Delay(8L,&ticks);
- HiliteControl((ControlHandle)h,false);
- }
- return(result);
- }
- //----------------------------------------------------------------------------------
- // Function: daEnterNumber
- // Purpose: restricts editText item to numeric input only.
- //
- // returns: false if keystroke should be processed by ModalDialog.
- //----------------------------------------------------------------------------------
- Boolean daEnterNumber(DialogPtr d, short i, long min, long max, char key)
- {
- Str255 s;
- short len;
- long num;
-
- if(daTEkey(key) || key == _PLUS || key == _MINUS)
- return(false);
- if(key < _ZERO || key > _NINE) {
- #ifdef BEEP
- SysBeep(1);
- #endif
- return(true);
- }
-
- DlgCut(d);
- daGetIText(d, i, s);
- len = s[0];
- s[++len] = key;
- s[0] = len;
- StringToNum(s, &num);
- if(num > max) {
- #ifdef BEEP
- DlgPaste(d);
- SysBeep(1);
- #endif
- return(true);
- }
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daEnterPassword
- // Purpose: restricts editText item to numeric input only.
- //
- // returns: false if keystroke should be processed by ModalDialog.
- //----------------------------------------------------------------------------------
- Boolean daEnterPassword(DialogPtr d, short i, short len, char key, Str255 pw)
- {
- Str255 s;
- short inx;
-
- if(key == _BACK) { // allow backspace to delete
- daSetIText(d, i, "\p");
- daGetIText(d, i, pw);
- return(true);
- }
- if(key == _TAB) // let TAB work
- return(false);
-
- if(daTEkey(key) || key == _DELKEY) { // disallow edit keys
- #ifdef BEEP
- SysBeep(1);
- #endif
- return(true);
- }
-
- if((**(*(DialogPeek)d).textH).selStart != // delete selection
- (**(*(DialogPeek)d).textH).selEnd) {
- TEDelete((*(DialogPeek)d).textH);
- daSetIText(d, i, "\p");
- daGetIText(d, i, pw);
- }
- daGetIText(d, i, s);
- if(s[0] < len) {
- TEKey('•',(*(DialogPeek)d).textH); // insert bullet
- inx = pw[0]; // now save real char in
- pw[++inx] = key; // the password buffer
- pw[0] = inx;
- }
- else
- #ifdef BEEP
- SysBeep(1);
- #endif
- return(true); // we did it, ModalDialog
- }
- //----------------------------------------------------------------------------------
- // Function: daLimitText
- // Purpose: restricts editText item to "count" number of characters.
- //
- // returns: false if keystroke should be processed by ModalDialog.
- //----------------------------------------------------------------------------------
- Boolean daLimitText(DialogPtr d, short i, short count, char key)
- {
- Str255 s;
-
- if(daTEkey(key))
- return(false);
-
- daGetIText(d, i, s);
- if(s[0] >= count) {
- #ifdef BEEP
- SysBeep(1);
- #endif
- return(true);
- }
- else
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daTEkey
- // Purpose: check for "edit" type keystroke.
- //
- // returns: true if key is an "edit" key.
- //----------------------------------------------------------------------------------
- Boolean daTEkey(char key)
- {
- if(key == _UP || key == _DOWN || key == _RIGHT || key == _LEFT ||
- key == _PAGEUP || key == _PAGEDOWN || key == _BACK || key == _TAB)
- return(true);
- return(false);
- }
- //----------------------------------------------------------------------------------
- // Function: daForwardDelete
- // Purpose: process a forward delete key in an editText item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- Boolean daForwardDel(DialogPtr d, char key)
- {
- if(key != _DELKEY)
- return(false);
-
- if((**(*(DialogPeek)d).textH).selStart ==
- (**(*(DialogPeek)d).textH).selEnd) {
- TESetSelect((**(*(DialogPeek)d).textH).selStart,
- (**(*(DialogPeek)d).textH).selEnd+1,
- (*(DialogPeek)d).textH);
- }
- TEDelete((*(DialogPeek)d).textH);
- return(true);
- }
- #pragma mark _DrawRoutines
-
- //----------------------------------------------------------------------------------
- // Function: daSetIDraw
- // Purpose: set a userItem drawProc.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daSetIDraw (DialogPtr d, short i, ProcPtr drawIt)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- if(t == userItem || t == itemDisable) {
- SetDItem(d, i, t, (Handle)drawIt, &r);
- }
- }
-
- //----------------------------------------------------------------------------------
- // Function: daDrawIFrame
- // Purpose: frame a userItem.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- pascal void daDrawIFrame(DialogPtr d, short i)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- FrameRect(&r);
- }
-
- #pragma mark _ItemDimming
- //----------------------------------------------------------------------------------
- // Function: daGetDim
- // Purpose: return state of DITL item.
- //
- // returns: true if dimmed (inactive control or disabled item)
- //----------------------------------------------------------------------------------
- Boolean daGetDim (DialogPtr d, short i)
- {
- short t;
- Handle h;
- Rect r;
-
- GetDItem(d, i, &t, &h, &r);
- if(h) {
- if(t & ctrlItem) {
- return(!(*(ControlHandle)h)->contrlHilite);
- }
- else
- return(t & itemDisable);
- }
- }
- //----------------------------------------------------------------------------------
- // Function: daDimItems
- // Purpose: dim a series of DITL items from first to last (must be sequential)
- // and draws them in gray.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daDimItems (DialogPtr d, short first, short last, Boolean dim)
- {
- short inx;
-
- for(inx=first;inx<=last;inx++)
- daDimOne(d, inx, dim);
- }
- //----------------------------------------------------------------------------------
- // Function: daDimOne
- // Purpose: dim (disable or inactivate) a single item.
- //
- // returns: void
- //----------------------------------------------------------------------------------
- void daDimOne (DialogPtr d, short i, Boolean dim)
- {
- short t;
- ControlHandle h;
- Rect r;
-
- GetDItem(d, i, &t, (Handle *)&h, &r);
- if(h) {
- if(t & ctrlItem) {
- if(dim)
- HiliteControl(h, DIM);
- else
- HiliteControl(h, NOTDIM);
- }
- else
- if((t & statText) || (t & editText))
- dimText(d, i, dim); // in dimText.c
- }
- }
-
- #pragma mark _UtilityRoutines
- //----------------------------------------------------------------------------------
- // Function: daGestalt
- // Purpose: call Gestalt if available.
- //
- // returns: Gestalt response
- //----------------------------------------------------------------------------------
- long daGestalt (OSType selector)
- {
- OSErr err;
- long gResult;
-
- if(trapAvailable(_Gestalt)) {
- err = Gestalt(selector,&gResult);
- if(err == noErr)
- return(gResult);
- }
- return(0L);
- }
-
- //----------------------------------------------------------------------------------
- // Function: daHasFeature
- // Purpose: call Gestalt to determine a given feature.
- //
- // returns: true if feature present
- //----------------------------------------------------------------------------------
- Boolean daHasFeature(OSType selector, short bitToCheck)
- {
- OSErr err;
- long gResult;
- Boolean result = false;
-
- if(trapAvailable(_Gestalt)) {
- err = Gestalt(selector,&gResult);
- if(err == noErr) {
- if(BitTst(&gResult, 31-bitToCheck))
- result = true;
- }
- }
- return(result);
- }
- //----------------------------------------------------------------------------------
- // Generic routine to see if a given trap is available
- //----------------------------------------------------------------------------------
- static Boolean trapAvailable(short theTrap)
- {
- TrapType tType;
-
- tType = getTrapType(theTrap);
-
- if(tType == ToolTrap) {
- theTrap &= 0x07ff;
- if(theTrap >= numToolBoxTraps())
- theTrap = _Unimplemented;
- }
- return(( NGetTrapAddress(theTrap, tType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap) ));
- }
-
- //----------------------------------------------------------------------------------
- // Needed for "trapAvailable" routine
- //----------------------------------------------------------------------------------
- static TrapType getTrapType(theTrap)
- short theTrap;
- {
- if((theTrap &= 0x0800))
- return(ToolTrap);
- return(OSTrap);
- }
- //----------------------------------------------------------------------------------
- // Needed for "trapAvailable" routine
- //----------------------------------------------------------------------------------
- static short numToolBoxTraps()
- {
- if(NGetTrapAddress(_InitGraf, ToolTrap) ==
- NGetTrapAddress(0xaa6e, ToolTrap))
- return(0x0200);
- return(0x0400);
- }
- //----------------------------------------------------------------------------------
- // Concatenates pascal strings - adds p2 to p1
- //----------------------------------------------------------------------------------
- extern void pStrCat(p1,p2)
- register char *p1, *p2;
- {
- register int i,j,k=0;
-
- i = p1[0];
- j = p2[0];
- p1[0] = i+j;
-
- while (++k<=j) p1[++i] = p2[k];
- }
-
- //----------------------------------------------------------------------------------
- // Copies pascal string - source to dest
- //----------------------------------------------------------------------------------
- extern void pStrCopy(char * source, char * dest)
- {
- short len;
-
- len = *dest++ = *source++;
- while (--len>=0)
- *dest++ = *source++;
- }
- extern void centerDialog(DialogPtr d)
- {
- short windW,windH;
- short rectW,rectH;
- Rect wRect;
-
- wRect = d->portRect;
-
- windW = wRect.right-wRect.left;
- windH = wRect.bottom-wRect.top;
-
- rectW = screenBits.bounds.right - screenBits.bounds.left;
- rectH = screenBits.bounds.bottom - screenBits.bounds.top;
-
- MoveWindow (d,
- screenBits.bounds.left+(rectW-windW)/2,
- screenBits.bounds.top+(rectH-windH)/3,
- false);
- }